package com.mc.typereference;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

public class ParentVo2ChildVo {

    public static <T> T change(ParentCo co, TypeReference<T> type) throws IOException {
        ObjectMapper objectMapper = new ObjectMapper();
        T vo = objectMapper.readValue(JSON.toJSONString(co), type);
        System.out.println(JSON.toJSON(vo));
        return vo;
    }

    public static void main(String[] args) throws IOException {
        ParentCo1 parentCo1 = new ParentCo1();
        (parentCo1).setDesc("test1");
        change(parentCo1, new TypeReference<ParentCo1>() {
        });
        ParentCo2 parentCo2 = new ParentCo2();
        (parentCo2).setDesc2("test1");
        change(parentCo2, new TypeReference<ParentCo2>() {
        });
    }


}
